//
//  SunNavController.m
//  Xspcf
//
//  Created by sunshine on 16/10/8.
//  Copyright © 2016年 sun. All rights reserved.
//

#import "SunNavController.h"
#import "ColorButton.h"

@interface SunNavController ()
@end

@implementation SunNavController


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count >=1) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        // 设置图片
        [btn setImage:[UIImage imageNamed:@"tool_back_black"] forState:UIControlStateNormal];
        // 设置尺寸
        [btn setFrame:CGRectMake(0, 0, 40, 20)];
        [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    }
    [super pushViewController:viewController animated:animated];
}
-(void)back{
    [self popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSMutableDictionary *barAttrs = [NSMutableDictionary dictionary];
    barAttrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:19];
    barAttrs[NSForegroundColorAttributeName] = [UIColor blackColor];
    NSMutableArray *colorArray1 = [@[[UIColor colorWithHexString:@"FFFFFF"],[UIColor colorWithHexString:@"FFFFFF"]] mutableCopy];
    ColorButton *cb = [[ColorButton alloc]initWithFrame:CGRectMake(0, 0,SCREENWIDTH, 44)];
    UIImage* backImage = [cb buttonImageFromColors:colorArray1 ByGradientType:leftToRight];
    [self.navigationBar setBackgroundImage:backImage forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    [self.navigationBar setTitleTextAttributes:barAttrs];
    // 阴影
    [self.navigationBar setShadowImage:[[UIImage alloc] init]];
    self.navigationBar.layer.shadowColor = [UIColor colorWithHexString:@"F78970"].CGColor;
    self.navigationBar.layer.shadowOffset = CGSizeMake(0, 2);
    self.navigationBar.layer.shadowOpacity = 0.06;
    

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

